package com.cpm.offcn.workqueue;

import com.cpm.offcn.utils.RabbitUtils;
import com.google.gson.Gson;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.tools.json.JSONUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class OrderSystem {
    public static void main(String[] args) throws IOException, TimeoutException {
         //获取长连接
        Connection connection = RabbitUtils.getConnection();
        //创建信道
        Channel channel = connection.createChannel();
        //绑定信道
        channel.queueDeclare("QUEUE_SMS",false,false,false,null);

        for (int i = 0; i < 100; i++) {
            SMS sms = new SMS("乘客"+i,"10000"+i,"购买成功");
            String message = new Gson().toJson(sms);
            //发送消息
            channel.basicPublish("","QUEUE_SMS",null,message.getBytes());
        }
        System.out.println("数据发送成功");
        channel.close();
        connection.close();
    }
}
